﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NS_DBOP;

public partial class Flow_FlowCustom : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            DataSet ds = new DBoperate().ExecuteQuery("select * from FlowType", 0, 0, "table1");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                this.drpFlowType.Items.Add(new ListItem(dr["Name"].ToString(), dr["ID"].ToString()));
            }
            this.drpFlowType.Items.Insert(0, "请选择");
            if (Request.QueryString["ID"] != null)
            {
                DataSet dsf = new DBoperate().ExecuteQuery("select * from Flow where ID=" + Request.QueryString["ID"], 0, 0, "flow");
                foreach (DataRow drf in dsf.Tables[0].Rows)
                {
                    this.txtName.Text = drf["Name"].ToString();
                    this.drpFlowType.SelectedItem.Value = drf["TypeID"].ToString();
                    this.txtContent.Text = drf["Des"].ToString();
                }
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string name = this.txtName.Text;
        //int userId = new DBoperate().ExecuteScalar("select Employeeid from Employee where username=" + Session["UserName"]);
        int userID = Convert.ToInt32(new DBoperate().ExecuteScalar("select Employeeid from Employee where username='yuguomin'"));
        string typeID = this.drpFlowType.SelectedItem.Value;
        string Des = this.txtContent.Text;
        if (Request.QueryString["ID"] != null)
        {
            string strsql = "update Flow set Name='" + name + "',TypeID=" + typeID
                + ",Des='" + Des + "',UserID=" + userID + "where ID=" + Request.QueryString["ID"];
            int result = new DBoperate().ExecuteUpdate(strsql);
            if (result > 0)
            {
                Response.Write("<script language=javascript>alert('保存成功！');window.location.href='FlowM.aspx'</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('保存失败！')</script>");
            }
        }
        else
        {

            string strsql = "insert into Flow values('" + name + "'," + typeID + ",'" + Des + "',0," + userID + ")";
            int result = new DBoperate().ExecuteUpdate(strsql);
            if (result > 0)
            {
                Response.Write("<script language=javascript>alert('保存成功！');window.location.href='FlowM.aspx'</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('保存失败！')</script>");
            }
        }
    }
    protected void btnReturn_Click(object sender, EventArgs e)
    {
        Response.Write("<script language=javascript>window.location.href='CustomList.aspx'</script>");
    }
}
